package com.example.widgetapplication;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener {
    public List<Manghe> goodsList0 = new ArrayList<>();
    private Goods goods = new Goods();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        Button btn1 = findViewById(R.id.btn_1);
        btn1.setOnClickListener(this);

        Button btn2 = findViewById(R.id.btn_2);
        btn2.setOnClickListener(this);

        Intent intent2 = getIntent();
        int goodsId = intent2.getIntExtra("goodsId",0);

        goodsList0 = goods.getGoodList();
        Manghe choosegoods = goodsList0.get(goodsId);
        ImageView goodsImg = findViewById(R.id.goods_image);
        TextView goodsName = findViewById(R.id.goods_name);
        goodsImg.setImageResource(choosegoods.getImageId());
        goodsName.setText(choosegoods.getName());
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_1:
                final String[] items = new String[]{"单个盲盒随机发不指定", "整盒8个款式不重复"};
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity2.this);
                builder.setTitle("您的选择是：");
                builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity2.this, "您加入" + items[i] + "到购物车", Toast.LENGTH_SHORT).show();
                    }
                });
                builder.setPositiveButton("确定", null);
                builder.create().show();
                break;
        }
        switch (view.getId()) {
            case R.id.btn_2:
                final String[] items = new String[]{"单个盲盒随机发不指定", "整盒8个款式不重复"};
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity2.this);
                builder.setTitle("您的选择是：");
                builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(MainActivity2.this, "您购买了" + items[i], Toast.LENGTH_SHORT).show();
                    }
                });
                builder.setPositiveButton("确定",null);
                builder.create().show();
                break;
        }


        }
    }